package com.googlecode.uipipedream;

import java.awt.Color;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * <p>
 * This file is part of UIPipeDream.
 * </p>
 * 
 * <p>
 * You can redistribute UIPipeDream and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 * </p>
 * 
 * <p>
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * </p>
 * 
 * <p>
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <a
 * href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>.
 * </p>
 * 
 * @author <a href="http://daemonsadvocate.blogspot.com/">Matthew B. Gray</a>
 * @author James Jones
 * @version 1.0 Final
 */
public class CSSGenerator {
	
	public CSSGenerator(){
		
	}
	
//	public static void main(String[] args) {
//		CSSGenerator cssg = new CSSGenerator();
//		cssg.generateCSS(Color.BLUE, Color.BLACK, Color.GREEN, Color.MAGENTA, Color.YELLOW);
//	}
	
	public static void generateCSS(File file, Color[] colours) throws IOException {
		BufferedWriter out = new BufferedWriter(new FileWriter(file));
		for (int i=0; i<colours.length; i++) {
			out.write(".colour"+i+"{ "); // classes named class1, class2...
			out.write("background-color: ");
			out.write("rgb("+colours[i].getRed()+","+colours[i].getGreen()+","+colours[i].getBlue()+") ");
			out.write("}\n");
		}
		out.close();
	}
	
	public static void generateCSS(File file, Color c1, Color c2, Color c3, Color c4, Color c5 ){
		
		String str1 = null;
		String str2 = null;
		String str3 = null;
		String str4 = null;
		String str5 = null;
		
		int r1 = c1.getRed();
		int g1 = c1.getGreen();
		int b1 = c1.getBlue();
		int r2 = c2.getRed();
		int g2 = c2.getGreen();
		int b2 = c2.getBlue();
		int r3 = c3.getRed();
		int g3 = c3.getGreen();
		int b3 = c3.getBlue();
		int r4 = c4.getRed();
		int g4 = c4.getGreen();
		int b4 = c4.getBlue();
		int r5 = c5.getRed();
		int g5 = c5.getGreen();
		int b5 = c5.getBlue();
		
		FileWriter fileWriter = null;
		
		try {
			fileWriter = new FileWriter(file);
		} catch (IOException e) {
			e.printStackTrace();
		}

		BufferedWriter buffWriter = new BufferedWriter(fileWriter);
		str1 = "body\n{\n background-color: rgb("+r1+","+g1+","+b1+");\n"+
		" font-family: sans-serif;\n text-align: center;\n width: 900px;\n margin: auto;\n margin-top: 10px;" +
		"\n font-size: 16pt;\n}";
		
		str2 = "h1\n{\n color: rgb("+r4+","+g4+","+b4+");\n}";
		
		str3 = "table\n{\n width:1200px;\n height:200px;\n Background: rgb("+r3+","+g3+","+b3+");\n text-align:center;\n}";
		
		str4 = "a\n{\n font-weight: bold;\n color: rgb("+r2+","+g2+","+b2+");\n font-size: 42pt;\n}" +
				"\np\n{\n color: rgb("+r4+","+g4+","+b4+");\n font-size: 16pt;\n}";
		
		str5 = "#banner\n{\n height: 137px;\n background-position: center;\n width: 1200px;\n margin: auto;" +
				"\n background-color: rgb("+r5+","+g5+","+b5+");\n}";
		try {
			buffWriter.write(str1);
			buffWriter.newLine();
			buffWriter.write(str2);
			buffWriter.newLine();
			buffWriter.write(str3);
			buffWriter.newLine();
			buffWriter.write(str4);
			buffWriter.newLine();
			buffWriter.write(str5);
			buffWriter.newLine();
			
			buffWriter.close();
			System.out.println("Completed CSS file generation");
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
